import os

import requests

from api import log
from config import HOST


#充值api
class ApiRecharge:
    #1.初始化
    def __init__(self,session):
        #获取session对象
        self.session=session
        #获取图片验证码封装
        self.__url_img_code=HOST+"/common/public/verifycode/{}"
        #充值url
        self.__url_recharge=HOST+"/trust/trust/recharge"

    #2、获取图片验证码接口 封装
    def url_img_code(self,random):
        log.info("正在调用 图片验证码接口 ,请求方法:{} ,url:{}, 参数为:{}".format("get", self.__url_img_code,random))
        return self.session.get(url=self.__url_img_code.format(random))

    #3、充值请求接口 封装
    def url_recharge(self,amount,valicode):
        data={
            "paymentType":"chinapnrTrust",
            "amount":amount,
            "formStr":"reForm",
            "valicode":valicode
        }
        log.info("正在调用 充值请求接口 ,请求方法:{} ,url:{}, 参数为:{}".format("post", self.__url_recharge, data))
        return self.session.post(url=self.__url_recharge,data=data)